package com.by.dao.impl;

import com.by.dao.tbDao;
import com.by.entity.tb;
import com.by.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class tbDaoImpl extends DBUtil implements tbDao {
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    @Override
    public List<tb> getAlltb() {
        List<tb> list = new ArrayList<>();
        String sql = "select * from tb";
        conn = getConn();
        try{
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            while(rs.next()){
                tb tb = new tb();
                tb.setId(rs.getInt("id"));
                tb.setUser_name(rs.getString("user_name"));
                tb.setCourse(rs.getString("course"));
                list.add(tb);
            }
        }catch (SQLException e){
            throw new RuntimeException(e);
        }finally{
            colseAll(conn,pstmt,rs);
        }



        return list;
    }
}
